/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database.dao;

import database.common.GenericDao;
import database.entity.Customers;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
/**
 *
 * @author Administrator
 */
public class CustomersDao extends GenericDao<Customers, Integer> {
    public List<Customers> search(String name, String address, String discountlvl, String start_time, String end_time) {
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();

        
        Criteria c = session.createCriteria(Customers.class);
        c.add(Restrictions.like("status", 0));
        if(!name.isEmpty()) c.add(Restrictions.like("name", "%"+name+"%"));
        if(!address.isEmpty()) c.add(Restrictions.like("address", "%"+address+"%"));
        if(!discountlvl.equals("All")) c.add(Restrictions.like("discountLevel", new Integer(discountlvl)));
        List<Customers> list = c.list();

        
        session.flush();
        session.getTransaction().commit();
        return list;
    }
    
    public List<Customers> getAllCustomer() {
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();

        
        Criteria c = session.createCriteria(Customers.class);
        c.add(Restrictions.like("status", 0));
        List<Customers> list = c.list();

        
        session.flush();
        session.getTransaction().commit();
        return list;
    }
}   

